from models import SimpleConfig

def get(name, default=None, config_object=SimpleConfig, add=True):
    try:
        return config_object.objects.get(key=name).value
    except config_object.DoesNotExist, e:
        if default != None:
            if add:
                set(name, default, config_object)
            return default
        else:
            raise e

def set(name, value, config_object=SimpleConfig):
    c, created = config_object.objects.get_or_create(key=name)
    c.value = value
    c.save()

def delete(name, value, config_object=SimpleConfig):
    try:
        o = config_object.objects.get(key=name)
        del o
    except config_object.DoesNotExist, e:
        pass